import cv2
import numpy as np
def nothing(x):
    pass


img_raw = cv2.imread('IMG2.jpeg')

img_raw = cv2.resize(img_raw,(600,800))
gray = cv2.cvtColor(img_raw, cv2.COLOR_BGR2GRAY)

blur = cv2.GaussianBlur(gray, (5,5), 0)

cv2.namedWindow("Trackbars")
cv2.createTrackbar("L - H", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("L - S", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("L - V", "Trackbars", 0, 255, nothing)
cv2.createTrackbar("U - H", "Trackbars", 255, 255, nothing)
cv2.createTrackbar("U - S", "Trackbars", 255, 255, nothing)
cv2.createTrackbar("U - V", "Trackbars", 255, 255, nothing)
while True:

    hsv = cv2.cvtColor(img_raw, cv2.COLOR_BGR2HSV)
    l_h = cv2.getTrackbarPos("L - H", "Trackbars")
    l_s = cv2.getTrackbarPos("L - S", "Trackbars")
    l_v = cv2.getTrackbarPos("L - V", "Trackbars")
    u_h = cv2.getTrackbarPos("U - H", "Trackbars")
    u_s = cv2.getTrackbarPos("U - S", "Trackbars")
    u_v = cv2.getTrackbarPos("U - V", "Trackbars")
    lower_blue = np.array([l_h, l_s, l_v])
    upper_blue = np.array([u_h, u_s, u_v])

    # mask = cv2.inRange(hsv, lower_blue, upper_blue)
    # result = cv2.bitwise_and(img_raw, img_raw, mask=mask)

    edged = cv2.Canny(blur, l_h, l_s)
    # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
    # gradient = cv2.morphologyEx(edged, cv2.MORPH_GRADIENT, kernel)

    cv2.imshow("frame", blur)
    # cv2.imshow("mask", mask)
    cv2.imshow("result", edged)
    key = cv2.waitKey(1)
    if key == 27:
        break

cv2.destroyAllWindows()